-----------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/juanpablouribetrujillo/My Drive (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analys
> is/../logs/optimality_conditions.log
  log type:  text
 opened on:  24 Jun 2024, 22:26:49

. *settings some settings that are common for the set of plots on this dofile;
.  local pdf_plot_settings =      `"
>                                 xmtick(1992(1)2008)
>                                 xlabel(1992(4)2008)
>                                 ylabel(#3,)
>                                 ymticks(##5)
>                                 scale(*1.5) 
>                                 xtitle("")
>                                 legend(off)"';

. *scale(*1.3): This rescales the font size of the whole figure;
.         ********************************************************************;
.         *parameters ;
. local iri_max=180;

. global delta =0.1;

. global delta10 =0.1;

. global kappa=0.0000016;

. *------------------------------------------------------------------------------;
. *1. Get Parameters for the parametric approaximation;
. *------------------------------------------------------------------------------;
. use "../data/hpms_hwy_stats_88_08.dta", clear  ;

. *---------------------------------------------------;
. * - Generate variables and general cleanings ;
. *---------------------------------------------------;
. do "_programs_sample";

. # d ;
delimiter now ;
. ****************************************;
.         *This program is used to add a row indicating the use of sample id when using areg;
. cap program drop add_lab_FE;

. program define add_lab_FE;
  1.         matrix V = [vecdiag(e(V)),1];
  2.         matrix V=diag(V);
  3.         matrix b=[e(b),1];
  4.         matrix colnames b= `:  colnames e(b)' `1';
  5.         matrix colnames V= `:  colnames e(V)' `1';
  6.         erepost b=b V=V ,rename;
  7. end;

. ****************************************;
.         *This program calculates summary stats for regression tables;
. cap program drop sum_stats;

. program define sum_stats;
  1.         sum Diri ;
  2.         estadd  scalar mean_Diri=r(mean) ;
  3.         sum aadt_10000  ;
  4.         estadd  scalar mean_aadt=r(mean) ;
  5.         sum I2_t ;
  6.         estadd  scalar mean_I2_t=r(mean) ;
  7.         sum I2_t_exp_I2  ;
  8.         estadd  scalar mean_I2_t_exp=r(mean) ;
  9.         end;

. ****************************************;
.         *This program plots year dummies;
. cap program drop plot_dummies;

. program define plot_dummies;
  1.         preserve;
  2.         *save se to disk;
.         mata: se=sqrt(diagonal(st_matrix("e(V)")));
  3.  // converts e(V) into se and placed in mata matrix se
>         clear;
  4.         getmata se, force ;
  5.         gen counter=_n;
  6.         save se,replace;
  7.                 *save coefficients to disk and organize;
.         mat beta=e(b);
  8.         mat list beta;
  9.         clear;
 10.         set obs 1;
 11.         svmat double beta;
 12.         *file in memory is a single row year effects from regression;
.         gen dummy=1;
 13.         reshape long beta,  i(dummy) j(year);
 14.         gen counter=_n;
 15.         *merge with se;
.         merge 1:1 counter using se;
 16.         drop if counter>17;
 17.         drop if beta==. | beta==0;
 18.         drop _merge counter;
 19.         *just keep year X expenditure coefficients;
.         drop if year==.;
 20.         replace year = year+1991;
 21.         sort year;
 22.         *file in memory gives bin, mean y and se;
.         gen up5 = beta+1.96*se;
 23.         gen down5 = beta-1.96*se;
 24.         save beta, replace;
 25.         *file in memory is a list of year by year inverse prices and CI's;
.         *settings for plots;
.         local pdf_plot_settings =       `"bgcolor(white) 
>                                         graphregion(color(white)) plotregion(ls(none))  
>                                                                 xmtick(1992(1)2008) 
>                                                                 ymtick(##5)
>                                                                 xlabel(1992(4)2008)
>                                         xtitle("")
>                                         legend(off)
>                                         scale(*1.5)
>                                         
>                                         "';
 26.                                         twoway rcap up5 down5 year, lstyle(ci)|| scatter beta year, `p
> df_plot_settings';
 27.         graph export "temp_t.pdf", replace;
 28.         erase se.dta;
 29.         erase beta.dta;
 30.         save "temp_betas.dta", replace;
 31.         restore;
 32. end;

. # d ;
delimiter now ;
. cap program drop plot_dummies_cons;

. program define plot_dummies_cons;
  1. args y_var controls;
  2.         matrix time_cons=J(17,3,.);
  3.         matrix colnames time_cons=year beta var;
  4.         local n=1;
  5.                 if "`controls'"==""{;
  6.                 forvalues year=1992(1)2008{;
  7.                                 reg `y_var' I2_t_x* ,  cluster(state);
  8.                                 nlcom _b[I2_t_x`year']+_b[_cons], post;
  9.                                 mat  time_cons[`n',1]=`year';
 10.                                 mat  time_cons[`n',2]=e(b);
 11.                                 mat  time_cons[`n',3]=e(V);
 12.                                 local n=`n'+1;
 13.                 }               ;
 14.         };
 15.                                         if "`controls'"=="state"{;
 16.                 forvalues year=1992(1)2008{;
 17.                                                                 areg Diri  I2_t_x*   ,  cluster(state)
>  abs(state ) ;
 18. ;
.                                 nlcom _b[I2_t_x`year']+_b[_cons], post;
 19.                                 mat  time_cons[`n',1]=`year';
 20.                                 mat  time_cons[`n',2]=e(b);
 21.                                 mat  time_cons[`n',3]=e(V);
 22.                                 local n=`n'+1;
 23.                 }               ;
 24.         };
 25.                                 if "`controls'"=="id"{;
 26.                 forvalues year=1992(1)2008{;
 27.                                                                 areg Diri  I2_t_x*   ,  cluster(state)
>  abs(id) ;
 28.                                 nlcom _b[I2_t_x`year']+_b[_cons], post;
 29.                                 mat  time_cons[`n',1]=`year';
 30.                                 mat  time_cons[`n',2]=e(b);
 31.                                 mat  time_cons[`n',3]=e(V);
 32.                                 local n=`n'+1;
 33.                 }               ;
 34.         };
 35.                                         preserve ;
 36.                                 clear ;
 37.                                 svmat time_cons, names(col) ;
 38.                                 gen se=var^(1/2);
 39.                                 gen up5 = beta+1.96*se;
 40.                                 gen down5 = beta-1.96*se;
 41.                                 save beta`y_var', replace;
 42.                                 *file in memory is a list of year by year inverse prices and CI's;
.                                 *settings for plots;
.                                 local pdf_plot_settings =       `"bgcolor(white) 
>                                                                 graphregion(color(white)) plotregion(ls(n
> one))  
>                                                                 xmtick(1992(1)2008) 
>                                                                 ymtick(##5)
>                                                                 xlabel(1992(4)2008)
>                                                                 legend(off)
>                                                                 xtitle("")
>                                                                 
>                                                                 scale(*1.5)"';
 43.                                 twoway rcap up5 down5 year, lstyle(ci)|| scatter beta year, `pdf_plot_
> settings';
 44.                                 graph export "temp_t.pdf", replace;
 45.                                                                                         restore ;
 46. end;

. # d cr ;
delimiter now cr
. 
. 
end of do-file

. do "_setup_expenditure.do";

. /******************************************************************
> 
> setup_expenditure.do
> 
> Subroutine to calculate expenditure variables for all analysis programs;
> 
> mt 20190506
> *******************************************************************/
. # delim ;  
delimiter now ;
. * expenditure on length and IRI from SF12a. Check that categories are right. Can we break apart ROW?;
. *conversion factor to get to 10^6 2010 dollars;
. gen deflate= 1/(ppiaco_2010*10);

. *gen deflate= 1;
. *consolidate rural and urban SF12a variables that we need;
. local rur_urb_list      "exp_eng_row_IH                 exp_row_IH              exp_eng_IH              e
> xp_new_cons_IH
>                         exp_relocation_IH               exp_recons_IH           exp_recons_add_IH       e
> xp_recons_noadd_IH
>                         exp_maj_wide_IH                 exp_R3_IH               exp_R3_min_wide_IH      e
> xp_R3_rehab_rest_IH    
>                         exp_R3_resurf_IH
>                         exp_new_bridge_IH exp_bridgereplacement_IH exp_majorbridgerehab_IH exp_minorbridg
> erehab_IH exp_bridge_IH
>                         ";

. foreach exp_var of local rur_urb_list{;
  2.                 replace `exp_var'_urban=cond(`exp_var'_urban==.,0,`exp_var'_urban);
  3.                 replace `exp_var'_rural=cond(`exp_var'_rural==.,0,`exp_var'_rural);
  4.                 gen `exp_var'_all = `exp_var'_urban + `exp_var'_rural;
  5.                 drop `exp_var'_urban `exp_var'_rural;
  6.                 };
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)
(889 real changes made)
(735 real changes made)

. *consolidate SF12a variables into nominal construction and resurfacing for pre and post 1998;
. *NB: exp_new_cons_IH_all and exp_maj_wide_IH_all are common to pre and post 1998 construction;
. gen exp_L_IH_SF12a_n_old=       exp_eng_row_IH_all + exp_new_cons_IH_all + exp_maj_wide_IH_all;

. gen exp_IRI_IH_SF12a_n_old=     exp_recons_IH_all  + exp_R3_IH_all;

.  gen exp_L_IH_SF12a_n_new=      exp_row_IH_all     + exp_eng_IH_all      + exp_new_cons_IH_all  + exp_rel
> ocation_IH_all + exp_maj_wide_IH_all;

.                         gen exp_IRI_IH_SF12a_n_new=     exp_recons_add_IH  + exp_recons_noadd_IH + exp_R3
> _min_wide_IH   + exp_R3_rehab_rest_IH  + exp_R3_resurf_IH;

. * Do the same for bridge expenditure ;
. gen exp_bridge_IH_SF12a_n_new=cond( year>1998,
>                                                                         exp_new_bridge_IH_all+exp_bridger
> eplacement_IH_all+exp_majorbridgerehab_IH_all+exp_minorbridgerehab_IH_all,.);
(147,240 missing values generated)

.                                                                         gen exp_bridge_IH_SF12a_n_old=con
> d( year<=1998,
>                                                                         exp_bridge_IH_all,.);
(160,858 missing values generated)

. *diagnostics -- should all be zero -- this test won't work for construction;
. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year>1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |    160,858    220065.6      226117          0    1142287
exp_IRI_IH~d |    160,858           0           0          0          0

. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year<=1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |    147,240           0           0          0          0
exp_IRI_IH~d |    147,240      107408      108656          0     560136

. *consolidate pre and post 1998 variable construction;
. gen exp_IRI_IH_SF12a_n =        cond(year>1998, exp_IRI_IH_SF12a_n_new, exp_IRI_IH_SF12a_n_old);

. gen exp_L_IH_SF12a_n =          cond(year>1998, exp_L_IH_SF12a_n_new, exp_L_IH_SF12a_n_old);

. gen exp_bridge_IH_SF12a_n =             cond(year>1998, exp_bridge_IH_SF12a_n_new, exp_bridge_IH_SF12a_n_
> old);

. *clean up -- save reloacation;
. gen temp = exp_relocation_IH_all;

. gen temp2 =exp_row_IH_all ;

. foreach exp_var of local rur_urb_list{;
  2.                 drop `exp_var'_all;
  3.                 };

.                 drop *_new *_old;

. rename temp exp_relocation_IH_all_n;

.  rename temp2 exp_row_IH_all_n ;

. *calculate total IH and SF12a maintenance;
. gen exp_IH_total_SF12_n = exp_IH_mtn_all + exp_IH_k_all;
(351 missing values generated)

. gen exp_IH_mtn_SF12a_n = exp_IH_total_SF12_n - exp_IRI_IH_SF12a_n - exp_L_IH_SF12a_n -exp_bridge_IH_SF12a
> _n;
(351 missing values generated)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%       -73065        -796329
 5%         4228        -796329
10%     7764.049        -796329       Obs             307,747
25%        19215        -796329       Sum of wgt.     307,747

50%        48833                      Mean           75766.26
                        Largest       Std. dev.      104646.2
75%     100944.5        2017193
90%     181282.9        2062267       Variance       1.10e+10
95%     237426.6        3278198       Skewness       2.799105
99%       458010        3303381       Kurtosis       40.18784

. replace exp_IH_mtn_SF12a_n= cond(exp_IH_mtn_SF12a_n<0,0,exp_IH_mtn_SF12a_n );
(5,948 real changes made)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%         4228              0
10%     7764.049              0       Obs             307,747
25%        19215              0       Sum of wgt.     307,747

50%        48833                      Mean            78426.6
                        Largest       Std. dev.      97296.26
75%     100944.5        2017193
90%     181282.9        2062267       Variance       9.47e+09
95%     237426.6        3278198       Skewness       4.440624
99%       458010        3303381       Kurtosis       45.17407

. ;
. *convert to real 2010 USD 10^6;
. *NB: deflate calculated in calling program;
. rename app_IH app_IH_n;

. rename exp_IH_mtn_all exp_IH_mtn_SF12_n;

. ren rev_grand_total_mt rev_grand_total_mt_n;

. ren rev_total_h rev_total_h_n;

. ren rev_total_mt rev_total_mt_n ;

. ren rev_total_m_fuel_h rev_total_m_fuel_h_n ;

. local real_list "exp_IH_total_SF12 exp_IH_mtn_SF12a exp_IRI_IH_SF12a exp_L_IH_SF12a app_IH exp_IH_mtn_SF1
> 2 exp_relocation_IH_all 
>                                  rev_grand_total_mt rev_total_h rev_total_mt rev_total_m_fuel_h
>                                  exp_bridge_IH_SF12a exp_row_IH_all
>                                  ";

. foreach exp_var of local real_list{;
  2.                 gen `exp_var'_r=deflate*`exp_var'_n;
  3.                 drop `exp_var'_n;
  4.                 };
(351 missing values generated)
(351 missing values generated)
(77,386 missing values generated)
(351 missing values generated)
(105,706 missing values generated)
(399 missing values generated)
(105,706 missing values generated)
(399 missing values generated)

.         forvalues i=1(1)5{;
  2.                                 gen deflate_L`i'= 1/(ppiaco_2010_L`i'*10);
  3.                 ren L`i'FHWA_apport_LW L`i'FHWA_apport_LW_n;
  4.                 gen L`i'FHWA_apport_LW_r=deflate_L`i'*L`i'FHWA_apport_LW_n;
  5.                 drop L`i'FHWA_apport_LW_n;
  6. };
(303 missing values generated)
(351 missing values generated)
(399 missing values generated)
(447 missing values generated)
(495 missing values generated)

.                                                 *label and drop superflous expenditure data;
. label var       exp_IH_total_SF12_r     "Total IH exp SF12 real";

. label var       exp_IH_mtn_SF12_r       "Total IH maint exp SF12 real";

. label var       exp_IH_mtn_SF12a_r      "Total IH maint exp SF12a real";

.  label var      exp_IRI_IH_SF12a_r      "Total IH IRI exp SF12a real";

.  label var      exp_L_IH_SF12a_r        "Total IH L exp SF12a real";

. label var       app_IH_r                "Total IH approp real";

. label var       exp_relocation_IH_all   "Total IH exp relocation, >1998";

. label var   rev_grand_total_mt_r          "Total revenue mass transit account real [source: FE9 p2 ]";

. label var   rev_total_mt_r        "Total revenue highway and mass transit account real [source: FE9 p2 ]"
> ;

. label var   rev_total_h  "Total revenue highway account real [source: FE9 p2 ]";

. label var rev_total_m_fuel_h                     "Total Revenue motor fuel  (Highway motor fuel) [source:
>  FE9 p1 ]";

.         *drop exp_IH_k_rural-exp_subtotal_mtn_urban;
. exit;

end of do-file

. do "_cleaning_and_new_variables_sample.do";

. # d ;
delimiter now ;
. *label variables to mathc the names in the tables ;
. label var exp_L_IH_SF12a_r "\( Y^L \)";

. label var  exp_IRI_IH_SF12a_r "\( Y^L\:in\:IRI \)";

. label var  exp_IH_mtn_SF12a_r "\( Y^L\: in\: Maint.\)";

. ****************************************************;
. *calculate differences in miles and IRI;
. *local D_vars "u_iri_IH u_iri_urban u_iri_rural u_lane_miles_IH u_lane_miles_rural u_lane_miles_urban";
. local D_vars iri ;

. sort state id year ;

. foreach varname of local D_vars{;
  2.         *changed from leads to lags, 20190429;
.         gen D`varname'=cond(
>                         id[_n]==id[_n-1]&
>                         state[_n]==state[_n-1]&
>                         `varname'[_n]!=.&`varname'[_n-1]!=.&
>                         `varname'[_n]!=0&`varname'[_n-1]!=0&
>                         year[_n]==year[_n-1]+1,
>                         `varname'[_n]-`varname'[_n-1],.);
  3.         gen lag_`varname'=cond(
>                         id[_n]==id[_n-1]&
>                         state[_n]==state[_n-1]&
>                         `varname'[_n]!=.&`varname'[_n-1]!=.&
>                         `varname'[_n]!=0&`varname'[_n-1]!=0&
>                         year[_n]==year[_n-1]+1,
>                         `varname'[_n-1],.);
  4.                                         };
(44,521 missing values generated)
(44,521 missing values generated)

. sum Diri d_iri;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        Diri |    263,577   -1.215084    28.56901       -554        592
       d_iri |    263,577   -1.215084    28.56901       -554        592

.         drop d_iri;

. ** indicator for states with maintenance reported in HPMS;
. *bysort state year : egen D_exp_I2=max(I2_t) if I2_t!=.;
.  *label var D_exp_I2 "Dummy=1 for state year if if at least one sample id reports maintenance";
.         *keep if _n<50;
. *Total lane miles IH in each state-year;
.  bysort state year : egen lane_miles_st=total(lane_miles);

. label var  lane_miles_st "Total IH lane miles in state year (HPMS-sample)" ;

. *Total lane miles resurfaced IH in each state-year;
.  gen lane_miles_x=I2_t*lane_miles;
(673 missing values generated)

. bysort state year : egen lane_milesI2_st=total(lane_miles_x);

. drop lane_miles_x;

. label var  lane_milesI2_st "Total I2 IH lane miles in state year (HPMS-sample)" ;

. *keep year state lane_miles lane_miles_st lane_milesI2_st I2_t;
. *order year state lane_miles lane_miles_st lane_milesI2_st I2_t;
. * Real IH Expenditure per IH lane mile;
. gen app_IH_plm=                 (app_IH_r/lane_miles_st );
(77,531 missing values generated)

. gen exp_IRI_IH_SF12a_plm=       (exp_IRI_IH_SF12a_r/lane_miles_st );
(673 missing values generated)

. gen exp_L_IH_SF12a_plm=         (exp_L_IH_SF12a_r/lane_miles_st );
(673 missing values generated)

. label var app_IH_plm            "Appropriations per lane mile" ;

. label var exp_IRI_IH_SF12a_plm  "Exp. Resurfacing per lane mile" ;

. label var exp_L_IH_SF12a_plm    "Exp. construction per lane mile" ;

. * Real IH Expenditure per resurfaced IH lane mile;
. gen app_IH_I2_plm=                      (app_IH_r/lane_milesI2_st );
(126,970 missing values generated)

. gen exp_IRI_IH_I2_SF12a_plm=            (exp_IRI_IH_SF12a_r/lane_milesI2_st );
(59,249 missing values generated)

. gen exp_L_IH_I2_SF12a_plm=              (exp_L_IH_SF12a_r/lane_milesI2_st );
(59,249 missing values generated)

. label var app_IH_I2_plm                 "Appropriations per resurf.lane m." ;

. label var exp_IRI_IH_I2_SF12a_plm       "Exp. Resurfacing per resurf. lane m." ;

. label var exp_L_IH_I2_SF12a_plm         "Exp. Construction per resurf.lane m." ;

. forvalues i=1(1)5{;
  2.                                 gen L`i'FHWA_apport_LW_r_plm=                   (L`i'FHWA_apport_LW_r/
> lane_milesI2_st );
  3. };
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)
(59,279 missing values generated)

.         tab state year if Diri==.;

                     |                             Book year
     State fips code |      1980       1981       1982       1983       1984       1985 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         1          1          1          1          1          1 |       439 
             ARIZONA |         1          1          1          1          1          1 |     1,064 
            ARKANSAS |         1          1          1          1          1          1 |       641 
          CALIFORNIA |         1          1          1          1          1          1 |     1,437 
            COLORADO |         1          1          1          1          1          1 |       492 
         CONNECTICUT |         1          1          1          1          1          1 |     1,397 
            DELAWARE |         1          1          1          1          1          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0          0 |        78 
             FLORIDA |         1          1          1          1          1          1 |     1,548 
             GEORGIA |         1          1          1          1          1          1 |     1,267 
               IDAHO |         1          1          1          1          1          1 |       492 
            ILLINOIS |         1          1          1          1          1          1 |       846 
             INDIANA |         1          1          1          1          1          1 |       683 
                IOWA |         1          1          1          1          1          1 |     2,175 
              KANSAS |         1          1          1          1          1          1 |       769 
            KENTUCKY |         1          1          1          1          1          1 |       767 
           LOUISIANA |         1          1          1          1          1          1 |     1,301 
               MAINE |         1          1          1          1          1          1 |     1,256 
            MARYLAND |         1          1          1          1          1          1 |       674 
       MASSACHUSETTS |         1          1          1          1          1          1 |     1,370 
            MICHIGAN |         1          1          1          1          1          1 |     1,280 
           MINNESOTA |         1          1          1          1          1          1 |       289 
         MISSISSIPPI |         1          1          1          1          1          1 |       497 
            MISSOURI |         1          1          1          1          1          1 |       537 
             MONTANA |         1          1          1          1          1          1 |       308 
            NEBRASKA |         1          1          1          1          1          1 |       243 
              NEVADA |         1          1          1          1          1          1 |       701 
       NEW HAMPSHIRE |         1          1          1          1          1          1 |       489 
          NEW JERSEY |         1          1          1          1          1          1 |       704 
          NEW MEXICO |         1          1          1          1          1          1 |       537 
            NEW YORK |         1          1          1          1          1          1 |       760 
      NORTH CAROLINA |         1          1          1          1          1          1 |       840 
        NORTH DAKOTA |         1          1          1          1          1          1 |       252 
                OHIO |         1          1          1          1          1          1 |     1,407 
            OKLAHOMA |         1          1          1          1          1          1 |     1,762 
              OREGON |         1          1          1          1          1          1 |       940 
        PENNSYLVANIA |         1          1          1          1          1          1 |     4,911 
        RHODE ISLAND |         1          1          1          1          1          1 |       278 
      SOUTH CAROLINA |         1          1          1          1          1          1 |       431 
        SOUTH DAKOTA |         1          1          1          1          1          1 |       528 
           TENNESSEE |         1          1          1          1          1          1 |     1,274 
               TEXAS |         1          1          1          1          1          1 |     1,487 
                UTAH |         1          1          1          1          1          1 |     1,019 
             VERMONT |         1          1          1          1          1          1 |       188 
            VIRGINIA |         1          1          1          1          1          1 |     1,073 
          WASHINGTON |         1          1          1          1          1          1 |       426 
       WEST VIRGINIA |         1          1          1          1          1          1 |     1,234 
           WISCONSIN |         1          1          1          1          1          1 |       930 
             WYOMING |         1          1          1          1          1          1 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |        48         48         48         48         48         48 |    44,521 


                     |                             Book year
     State fips code |      1986       1987       1988       1989       1990       1991 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         1          1        145        145          1          2 |       439 
             ARIZONA |         1          1        174        177          0          1 |     1,064 
            ARKANSAS |         1          1        123        123         67         62 |       641 
          CALIFORNIA |         1          1        400        400          9         32 |     1,437 
            COLORADO |         1          1        246          7          6          1 |       492 
         CONNECTICUT |         1          1        226        230         19         18 |     1,397 
            DELAWARE |         1          1         23         25          1          0 |       111 
DISTRICT OF COLUMBIA |         0          0         15         15         15          0 |        78 
             FLORIDA |         1          1        276        279        280         22 |     1,548 
             GEORGIA |         1          1        283          8          1          3 |     1,267 
               IDAHO |         1          1        169        170          1          6 |       492 
            ILLINOIS |         1          1        306          0          3         61 |       846 
             INDIANA |         1          1        162        162        166          2 |       683 
                IOWA |         1          1        423        423        423        114 |     2,175 
              KANSAS |         1          1        186        189         58         55 |       769 
            KENTUCKY |         1          1        215        219          0          0 |       767 
           LOUISIANA |         1          1        184        203        203         44 |     1,301 
               MAINE |         1          1        168        168        168          2 |     1,256 
            MARYLAND |         1          1        196         45         49         65 |       674 
       MASSACHUSETTS |         1          1        427        427          5          1 |     1,370 
            MICHIGAN |         1          1        373        374         14         29 |     1,280 
           MINNESOTA |         1          1        148          1          0          4 |       289 
         MISSISSIPPI |         1          1        163        170          2          0 |       497 
            MISSOURI |         1          1        153        153          2          1 |       537 
             MONTANA |         1          1        196         16          0          0 |       308 
            NEBRASKA |         1          1         89         89          0          2 |       243 
              NEVADA |         1          1        151        152          0          0 |       701 
       NEW HAMPSHIRE |         1          1        118        118          0          0 |       489 
          NEW JERSEY |         1          1        169        181         40         34 |       704 
          NEW MEXICO |         1          1        262         27          4          0 |       537 
            NEW YORK |         1          1        315          2          0         20 |       760 
      NORTH CAROLINA |         1          1        158        159         46         21 |       840 
        NORTH DAKOTA |         1          1        110        110          1          1 |       252 
                OHIO |         1          1        401        397         77          0 |     1,407 
            OKLAHOMA |         1          1        247        425        216        220 |     1,762 
              OREGON |         1          1        202        202          0          1 |       940 
        PENNSYLVANIA |         1          1        749      1,532        287         84 |     4,911 
        RHODE ISLAND |         1          1         42         42         42          0 |       278 
      SOUTH CAROLINA |         1          1        141        141          2          0 |       431 
        SOUTH DAKOTA |         1          1        134        134          5          0 |       528 
           TENNESSEE |         1          1        252        252          0          0 |     1,274 
               TEXAS |         1          1        406          3          1          9 |     1,487 
                UTAH |         1          1        289        290          1          3 |     1,019 
             VERMONT |         1          1         90         56          0          0 |       188 
            VIRGINIA |         1          1        243        243          5          0 |     1,073 
          WASHINGTON |         1          1        199          2          1          0 |       426 
       WEST VIRGINIA |         1          1        383        400          0         20 |     1,234 
           WISCONSIN |         1          1        164        164        165          3 |       930 
             WYOMING |         1          1        121        123         49          9 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |        48         48     10,815      9,373      2,435        952 |    44,521 


                     |                             Book year
     State fips code |      1992       1993       1994       1995       1996       1997 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |        11         48          8          0          1          0 |       439 
             ARIZONA |         2         57          0          4        417          0 |     1,064 
            ARKANSAS |        26         29         42          5          2          5 |       641 
          CALIFORNIA |        21        239          7          4         12         19 |     1,437 
            COLORADO |        22         52          7         11          4          2 |       492 
         CONNECTICUT |        25        128          6        285        273         15 |     1,397 
            DELAWARE |         0         33          0          4          0          0 |       111 
DISTRICT OF COLUMBIA |         0         15          0          0          0          0 |        78 
             FLORIDA |         2        138         70         15         62         49 |     1,548 
             GEORGIA |        24        139        131         96         97         96 |     1,267 
               IDAHO |        10          0          0          0          0          2 |       492 
            ILLINOIS |        76        221         92         10          3          1 |       846 
             INDIANA |         9          2         60          5          2          4 |       683 
                IOWA |        39        392         23         55         46         22 |     2,175 
              KANSAS |        76        100          3          2          3          3 |       769 
            KENTUCKY |        10         84          5          1          1          0 |       767 
           LOUISIANA |        65        104         46         43         34         18 |     1,301 
               MAINE |         1         12         64          6          6          7 |     1,256 
            MARYLAND |        51        144          4         10          7          2 |       674 
       MASSACHUSETTS |         0        300         16          0          4         10 |     1,370 
            MICHIGAN |        48        156         86         80          1          0 |     1,280 
           MINNESOTA |         2         53          0          0          1          1 |       289 
         MISSISSIPPI |         5         35          0         10          5          4 |       497 
            MISSOURI |         9         62          3          0          0          0 |       537 
             MONTANA |         6         29          6          6          6          0 |       308 
            NEBRASKA |         4         22          8          0          0          0 |       243 
              NEVADA |        11        158        156         18         13          1 |       701 
       NEW HAMPSHIRE |         3          3          0          0          0          0 |       489 
          NEW JERSEY |         9          8        135          6          4          6 |       704 
          NEW MEXICO |         8          1         47          2          0          1 |       537 
            NEW YORK |        13        235          4          6          4          4 |       760 
      NORTH CAROLINA |        51        103         10         21          7          4 |       840 
        NORTH DAKOTA |         1          1          0          0          0          9 |       252 
                OHIO |         7        242         39          2          4          0 |     1,407 
            OKLAHOMA |         9        441          0         20          0          0 |     1,762 
              OREGON |         2         54          1          0          0          0 |       940 
        PENNSYLVANIA |       163        666          0         28        119         65 |     4,911 
        RHODE ISLAND |         3         36          0          0          0         46 |       278 
      SOUTH CAROLINA |         2         55         21          4          0          0 |       431 
        SOUTH DAKOTA |         0        117          3          5          2         16 |       528 
           TENNESSEE |       253        253          3          5         21         25 |     1,274 
               TEXAS |         2         27        129        151        135         15 |     1,487 
                UTAH |        28         94          2          1          3          0 |     1,019 
             VERMONT |         2          0          0          0          0          0 |       188 
            VIRGINIA |         1        135         25          0          0          0 |     1,073 
          WASHINGTON |        47         52          0          0          0          0 |       426 
       WEST VIRGINIA |         0         13          0          5          0          0 |     1,234 
           WISCONSIN |        11         45          5          3         19          0 |       930 
             WYOMING |        18          2         27          0          0          0 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |     1,188      5,335      1,294        929      1,318        452 |    44,521 


                     |                             Book year
     State fips code |      1998       1999       2000       2001       2002       2003 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         0         22          3          0          2          0 |       439 
             ARIZONA |         0          0          0         29          1         66 |     1,064 
            ARKANSAS |         5         14         69          2          1          0 |       641 
          CALIFORNIA |        89          9         17          0          9          8 |     1,437 
            COLORADO |         3         13         10          3          1         27 |       492 
         CONNECTICUT |         2         45         18          2         76          7 |     1,397 
            DELAWARE |         0          0          0          0          1          1 |       111 
DISTRICT OF COLUMBIA |         0         15          1          1          1          0 |        78 
             FLORIDA |        32         70         33         28         51         11 |     1,548 
             GEORGIA |        73         53         25          6          0         11 |     1,267 
               IDAHO |         1         61         21          0          0         14 |       492 
            ILLINOIS |         0         23          0          2          5          1 |       846 
             INDIANA |         2         55          0          0          2          0 |       683 
                IOWA |        20         59         19          3         16         29 |     2,175 
              KANSAS |         7         21         20          5          5          2 |       769 
            KENTUCKY |         0         16          7        127          1         31 |       767 
           LOUISIANA |         6        118          3          2         23         20 |     1,301 
               MAINE |        33        115         52          0          4         10 |     1,256 
            MARYLAND |         3         14          3          3         13         35 |       674 
       MASSACHUSETTS |        16          7          5          0         31         57 |     1,370 
            MICHIGAN |         0         14          1         11          0         43 |     1,280 
           MINNESOTA |         0         19          0          0          1          3 |       289 
         MISSISSIPPI |         4         14          0          4          5         27 |       497 
            MISSOURI |         1          8          0          6          0          5 |       537 
             MONTANA |         0          8          0          0          0         16 |       308 
            NEBRASKA |         0          1          9          0          0          2 |       243 
              NEVADA |         0          2          0          0          0          0 |       701 
       NEW HAMPSHIRE |         0         24         79         32          0         51 |       489 
          NEW JERSEY |         5          9         12          3          1         46 |       704 
          NEW MEXICO |         1         90          7          0         14         12 |       537 
            NEW YORK |         0         30          0          0          8          0 |       760 
      NORTH CAROLINA |        11         51         14          3         30         30 |       840 
        NORTH DAKOTA |         0          0          0          0          0          2 |       252 
                OHIO |         1         86          1          4          1         60 |     1,407 
            OKLAHOMA |         0         59          3          9         10         60 |     1,762 
              OREGON |         0        308         27         27          0          3 |       940 
        PENNSYLVANIA |         3         31         21         88        471        264 |     4,911 
        RHODE ISLAND |        46          1          3          3          0          0 |       278 
      SOUTH CAROLINA |         0          7          0          0          0          8 |       431 
        SOUTH DAKOTA |        24         35          5          1          4          4 |       528 
           TENNESSEE |        26         25         10          3         30         69 |     1,274 
               TEXAS |         3        162          6          5         60        160 |     1,487 
                UTAH |         3        133         65         11         11         16 |     1,019 
             VERMONT |         0          8          0          0          1          0 |       188 
            VIRGINIA |         1        325          4          6         17         10 |     1,073 
          WASHINGTON |         0         33          0          0          0          5 |       426 
       WEST VIRGINIA |         1         15         85          0          7          0 |     1,234 
           WISCONSIN |         6         14        208          0          1         57 |       930 
             WYOMING |        23          0          0          0          0          0 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |       451      2,242        866        429        915      1,283 |    44,521 


                     |                             Book year
     State fips code |      2004       2005       2006       2007       2008       2009 |     Total
---------------------+------------------------------------------------------------------+----------
             ALABAMA |         6         10          1          9         11          1 |       439 
             ARIZONA |        71          1          1          0         49          1 |     1,064 
            ARKANSAS |        10         23         16          3          0          1 |       641 
          CALIFORNIA |        18         43         69          7         11          1 |     1,437 
            COLORADO |         3         34         21          0          5          1 |       492 
         CONNECTICUT |         3          1          3          1          0          1 |     1,397 
            DELAWARE |         0          2          7          0          0          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0          0 |        78 
             FLORIDA |        49         40          6          6         15          1 |     1,548 
             GEORGIA |        69          9         14         60         55          1 |     1,267 
               IDAHO |         2         19          1          1          0          1 |       492 
            ILLINOIS |        12          6          9          1          0          1 |       846 
             INDIANA |         1          0          0         33          2          1 |       683 
                IOWA |        13         11          6          8         17          1 |     2,175 
              KANSAS |        14          5          0          1          0          1 |       769 
            KENTUCKY |        12          0          3          7         14          1 |       767 
           LOUISIANA |        42         44         20         32         33          1 |     1,301 
               MAINE |       302         42         74          8          0          1 |     1,256 
            MARYLAND |        15          1          0          0          0          1 |       674 
       MASSACHUSETTS |        15         12          7          8          8          1 |     1,370 
            MICHIGAN |        10         13         11          2          0          1 |     1,280 
           MINNESOTA |        28          0          0          8          6          1 |       289 
         MISSISSIPPI |         6          5         15          3          6          1 |       497 
            MISSOURI |        63          4          1         50          2          1 |       537 
             MONTANA |         2          2          1          0          0          1 |       308 
            NEBRASKA |         2          0          1          0          0          1 |       243 
              NEVADA |        21          2          0          0          2          1 |       701 
       NEW HAMPSHIRE |        27          1          2          3         14          1 |       489 
          NEW JERSEY |         2          5          5          3          7          1 |       704 
          NEW MEXICO |        15          0          0          0         32          1 |       537 
            NEW YORK |         0          0         82          9         14          1 |       760 
      NORTH CAROLINA |         4         95          0          4          4          1 |       840 
        NORTH DAKOTA |         2          0          1          0          0          1 |       252 
                OHIO |        45         24          2          0          0          1 |     1,407 
            OKLAHOMA |         0         13         13          3          0          1 |     1,762 
              OREGON |        82          4          6          4          3          1 |       940 
        PENNSYLVANIA |       135         25         12         65         89          1 |     4,911 
        RHODE ISLAND |         0          0          0          0          0          1 |       278 
      SOUTH CAROLINA |         3         23          0          8          2          1 |       431 
        SOUTH DAKOTA |        15          0          0         10          0          1 |       528 
           TENNESSEE |        32          0          0          1          0          1 |     1,274 
               TEXAS |        21         39         43         12         84          1 |     1,487 
                UTAH |        27          1          7          2         18          1 |     1,019 
             VERMONT |         0         17          0          0          0          1 |       188 
            VIRGINIA |        25         15          0          2          2          1 |     1,073 
          WASHINGTON |        31          0          0         24         18          1 |       426 
       WEST VIRGINIA |         0         56        182         18         35          1 |     1,234 
           WISCONSIN |        44          2          2          0          3          1 |       930 
             WYOMING |         0          0          2          1          0          1 |       389 
---------------------+------------------------------------------------------------------+----------
               Total |     1,299        649        646        417        561         48 |    44,521 


                     |                       Book year
     State fips code |      2010       2011       2012       2013       2014 |     Total
---------------------+-------------------------------------------------------+----------
             ALABAMA |         1          1          1          1          1 |       439 
             ARIZONA |         1          1          1          1          1 |     1,064 
            ARKANSAS |         1          1          1          1          1 |       641 
          CALIFORNIA |         1          1          1          1          1 |     1,437 
            COLORADO |         1          1          1          1          1 |       492 
         CONNECTICUT |         1          1          1          1          1 |     1,397 
            DELAWARE |         1          1          1          1          1 |       111 
DISTRICT OF COLUMBIA |         0          0          0          0          0 |        78 
             FLORIDA |         1          1          1          1          1 |     1,548 
             GEORGIA |         1          1          1          1          1 |     1,267 
               IDAHO |         1          1          1          1          1 |       492 
            ILLINOIS |         1          1          1          1          1 |       846 
             INDIANA |         1          1          1          1          1 |       683 
                IOWA |         1          1          1          1          1 |     2,175 
              KANSAS |         1          1          1          1          1 |       769 
            KENTUCKY |         1          1          1          1          1 |       767 
           LOUISIANA |         1          1          1          1          1 |     1,301 
               MAINE |         1          1          1          1          1 |     1,256 
            MARYLAND |         1          1          1          1          1 |       674 
       MASSACHUSETTS |         1          1          1          1          1 |     1,370 
            MICHIGAN |         1          1          1          1          1 |     1,280 
           MINNESOTA |         1          1          1          1          1 |       289 
         MISSISSIPPI |         1          1          1          1          1 |       497 
            MISSOURI |         1          1          1          1          1 |       537 
             MONTANA |         1          1          1          1          1 |       308 
            NEBRASKA |         1          1          1          1          1 |       243 
              NEVADA |         1          1          1          1          1 |       701 
       NEW HAMPSHIRE |         1          1          1          1          1 |       489 
          NEW JERSEY |         1          1          1          1          1 |       704 
          NEW MEXICO |         1          1          1          1          1 |       537 
            NEW YORK |         1          1          1          1          1 |       760 
      NORTH CAROLINA |         1          1          1          1          1 |       840 
        NORTH DAKOTA |         1          1          1          1          1 |       252 
                OHIO |         1          1          1          1          1 |     1,407 
            OKLAHOMA |         1          1          1          1          1 |     1,762 
              OREGON |         1          1          1          1          1 |       940 
        PENNSYLVANIA |         1          1          1          1          1 |     4,911 
        RHODE ISLAND |         1          1          1          1          1 |       278 
      SOUTH CAROLINA |         1          1          1          1          1 |       431 
        SOUTH DAKOTA |         1          1          1          1          1 |       528 
           TENNESSEE |         1          1          1          1          1 |     1,274 
               TEXAS |         1          1          1          1          1 |     1,487 
                UTAH |         1          1          1          1          1 |     1,019 
             VERMONT |         1          1          1          1          1 |       188 
            VIRGINIA |         1          1          1          1          1 |     1,073 
          WASHINGTON |         1          1          1          1          1 |       426 
       WEST VIRGINIA |         1          1          1          1          1 |     1,234 
           WISCONSIN |         1          1          1          1          1 |       930 
             WYOMING |         1          1          1          1          1 |       389 
---------------------+-------------------------------------------------------+----------
               Total |        48         48         48         48         48 |    44,521 

. *drop state-years with no resurfacing expenditure;
. drop if exp_IRI_IH_SF12a_r==0;
(5,758 observations deleted)

. drop if exp_IRI_IH_SF12a_r==.;
(0 observations deleted)

. *drop id-years with bad IRI data;
. drop if Diri==.;
(41,806 observations deleted)

. drop if abs(Diri)>200;
(344 observations deleted)

. *drop state-years with no resurfacing;
. drop if lane_milesI2_st==.|lane_milesI2_st==0;
(50,587 observations deleted)

. *drop DC and years outside sample;
. drop if state==11;
(0 observations deleted)

. drop if year<1992;
(23,548 observations deleted)

. drop if year>2008;
(0 observations deleted)

. tab state;

     State fips code |      Freq.     Percent        Cum.
---------------------+-----------------------------------
             ALABAMA |      1,169        0.63        0.63
             ARIZONA |      8,057        4.33        4.96
            ARKANSAS |      1,877        1.01        5.97
          CALIFORNIA |      6,247        3.36        9.33
            COLORADO |      2,132        1.15       10.47
         CONNECTICUT |      3,652        1.96       12.43
            DELAWARE |        171        0.09       12.53
             FLORIDA |      4,462        2.40       14.92
             GEORGIA |      3,607        1.94       16.86
               IDAHO |      2,799        1.50       18.37
            ILLINOIS |      3,718        2.00       20.37
                IOWA |      3,932        2.11       22.48
              KANSAS |      1,762        0.95       23.43
            KENTUCKY |      2,749        1.48       24.90
           LOUISIANA |      2,098        1.13       26.03
               MAINE |      2,057        1.11       27.14
            MARYLAND |      4,420        2.38       29.51
       MASSACHUSETTS |      2,135        1.15       30.66
            MICHIGAN |      4,737        2.55       33.21
           MINNESOTA |      2,251        1.21       34.42
         MISSISSIPPI |      1,197        0.64       35.06
            MISSOURI |      1,555        0.84       35.89
             MONTANA |      2,911        1.56       37.46
            NEBRASKA |      1,643        0.88       38.34
              NEVADA |      1,363        0.73       39.08
       NEW HAMPSHIRE |      1,884        1.01       40.09
          NEW JERSEY |      2,593        1.39       41.48
          NEW MEXICO |      2,201        1.18       42.66
            NEW YORK |      5,272        2.83       45.50
      NORTH CAROLINA |      4,507        2.42       47.92
        NORTH DAKOTA |      1,623        0.87       48.79
                OHIO |      7,468        4.01       52.81
            OKLAHOMA |      2,488        1.34       54.14
              OREGON |      5,303        2.85       56.99
        PENNSYLVANIA |     47,182       25.36       82.35
        RHODE ISLAND |        325        0.17       82.53
      SOUTH CAROLINA |      1,111        0.60       83.12
        SOUTH DAKOTA |      2,865        1.54       84.66
           TENNESSEE |      2,181        1.17       85.84
               TEXAS |      7,085        3.81       89.64
                UTAH |      2,588        1.39       91.04
             VERMONT |      1,326        0.71       91.75
            VIRGINIA |      2,191        1.18       92.93
          WASHINGTON |      2,366        1.27       94.20
       WEST VIRGINIA |      6,434        3.46       97.66
           WISCONSIN |      2,491        1.34       98.99
             WYOMING |      1,870        1.01      100.00
---------------------+-----------------------------------
               Total |    186,055      100.00

. *aadt variables;
.         gen aadt2_10000=aadt_1000^2;

. label var aadt2_10000 "(`:  var label aadt_1000')^2" ;

. gen aadt3_10000=aadt_1000^3;

. label var aadt3_10000 "(`:  var label aadt_1000')^3" ;

.         *Set up state year and I2 x year FE;
. *calculate number of years that each state is present in data;
. preserve;

.         sort state year;

.         by state year: gen counter1=_n;

.         keep if counter1==1;
(185,480 observations deleted)

.         display "count number of stateXyears for reference";
count number of stateXyears for reference

.         sum year;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        year |        575     1999.61    4.837559       1992       2008

.         sort state;

.         by state: gen num_years=_N;

.         by state: gen counter3=_n;

.         keep if counter3==1;
(528 observations deleted)

.         label var num_years "Years state present in data";

.         keep state num_years;

.         tab num_years;

Years state |
 present in |
       data |      Freq.     Percent        Cum.
------------+-----------------------------------
          5 |          2        4.26        4.26
          6 |          1        2.13        6.38
          7 |          2        4.26       10.64
          8 |          3        6.38       17.02
          9 |          5       10.64       27.66
         10 |          6       12.77       40.43
         12 |          2        4.26       44.68
         13 |          2        4.26       48.94
         14 |         10       21.28       70.21
         15 |          5       10.64       80.85
         16 |          2        4.26       85.11
         17 |          7       14.89      100.00
------------+-----------------------------------
      Total |         47      100.00

.         display "states present 1990-2008 --- use Texas 1990 for omitted state-year";
states present 1990-2008 --- use Texas 1990 for omitted state-year

.         tab state if num_years==18;
no observations

.         tab state if num_years==18, nol;
no observations

. // Texas, fips 48 is present in all years
>         sort state;

.         save stateyears,replace;
(file stateyears.dta not found)
file stateyears.dta saved

. restore;

. merge m:1 state using stateyears;
(label fips already defined)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                           186,055  (_merge==3)
    -----------------------------------------

. tab _merge;

   Matching result from |
                  merge |      Freq.     Percent        Cum.
------------------------+-----------------------------------
            Matched (3) |    186,055      100.00      100.00
------------------------+-----------------------------------
                  Total |    186,055      100.00

. order state state_name year num_years;

. erase stateyears.dta;

. *make state-year indicators for state years present in data;
.         levelsof year, local(year_list);
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. levelsof state, local(state_list);
1 4 5 6 8 9 10 12 13 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46
>  47 48 49 50 51 53 54 55 56

. display "`state_list'";
1 4 5 6 8 9 10 12 13 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46
>  47 48 49 50 51 53 54 55 56

. display "`year_list'";
1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008

. local i_stateyear=1;

. foreach k_year of local year_list{;
  2.         foreach k_state of local state_list{;
  3.                 if !("`k_year'"=="1990"&"`k_state'"=="48"){;
  4.  //texas 1990 omitted
>                         *make dummy for state-year;
.                         gen stateXyearI_`k_year'_`k_state'=cond(year==`k_year'&state==`k_state',1,0);
  5.                         *drop indicator if state-year missing from data;
.                         quiet sum stateXyearI_`k_year'_`k_state';
  6.                         local tester =r(mean) ;
  7.                         if `tester'==0{;
  8.                                 drop stateXyearI_`k_year'_`k_state';
  9.                                 };
 10.                         *increment counter if state-year present in data. counter is just used as a di
> agnostic;
.                         if `tester'>0{;
 11.                                 local ++i_stateyear;
 12.                                 };
 13.                         };
 14. //end skip texas 1990 if
>                 };
